package com.wanxi;

import java.util.Scanner;

public class TranslatorApp {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        Translator translator = new Translator();

        while (true) {
            System.out.println("-------1 添加词到词库中-------");
            System.out.println("-------2 查询词的详细信息-------");
            System.out.println("-------3 修改词的详细信息-------");
            System.out.println("-------4 全部详细信息-------");
            System.out.println("-------5 退出系统-------");
            System.out.println("请输入你的操作选择：");
            int chosen = scanner.nextInt();
            switch (chosen) {
                case 1:
                    System.out.println("请输入你要添加的词名: ");
                    String wordName = scanner.next();
                    System.out.println("请输入你要添加的词性: ");
                    String partOfSpeech = scanner.next();
                    System.out.println("请输入你要添加的词义: ");
                    String meaning = scanner.next();
                    System.out.println("请输入你要添加的例句: ");
                    String example = scanner.next();
                    Word word = new Word(wordName, partOfSpeech, meaning, example);
                    if (translator.addContent(word)) {
                        System.out.println("添加成功，可以通过操作2查询该词信息");
                    } else {
                        System.out.println("添加失败，词库中已有该词，请不要重复添加");
                    }
                    break;

                case 2:
                    System.out.println("请输入你要查询的词名");
                    String oneWordName = scanner.next();
                    String content = translator.inquireContent(oneWordName);
                    System.out.println(content);
                    break;

                case 3:
                    System.out.println("请输入你要修改的词名: ");
                    String theWordName = scanner.next();
                    System.out.println("请输入你要修改的词性: ");
                    String thePartOfSpeech = scanner.next();
                    System.out.println("请输入你要修改的词义: ");
                    String theMeaning = scanner.next();
                    System.out.println("请输入你要修改的例句: ");
                    String theExample = scanner.next();
                    Word theWord = new Word(theWordName, thePartOfSpeech, theMeaning, theExample);
                    if (translator.amendContent(theWord)) {
                        System.out.println("修改成功");
                    } else {
                        System.out.println("修改失败，词库中没有该词，请先添加");
                    }
                    break;

                case 4:
                    System.out.println("该词库的全部内容如下： " + "\n");
                    translator.allContent();
                    break;

                case 5:
                    System.out.print("正在退出系统 ");
                    for (int i = 3; i >= 0; i--) {
                        try {
                            Thread.sleep(500);
                        } catch (InterruptedException e) {
                            e.printStackTrace();
                        }
                        System.out.print(i + " ");
                    }
                    System.exit(0);

                default:
                    System.out.println("输出操作不正常，请重新输入");

            }

        }

    }
}
